package com.power.sifa.approve.model.enumeration;

import cn.hutool.core.util.ObjectUtil;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;


/**
 * @ClassName Tp_proctypeEnum
 * @Author xiongzw
 * @Date 2023/9/8 16:38
 * @Description
 * @Version: 1.0
 **/
@Getter
public enum Tp_proctypeEnum {

    /**
     * 受理环节
     */
    // 受理前调解- 受理调解
    // Tp_procmaterialEnum.MATER_MEAPPLY, Tp_procmaterialEnum.MATER_MEREGISTER,Tp_procmaterialEnum.MATER_MERECORD, Tp_procmaterialEnum.MATER_MEACCORD
    MATER_MEDIATE("mater_mediate", Tp_proctype.MATER_MEDIATE, "受理前调解", "受理前调解",
            Tp_categoryEnum.MEDIATE_UPLOAD.getKey(), "ADMRE_AUDIT_MEDIATE", null, null),

    ACCEPT_ACCEPT("accept_accept", Tp_proctype.ACCEPT_ACCEPT, "受理", "受理",
            Tp_categoryEnum.ACCEPT_UPLOAD.getKey(), "ADMRE_AUDIT_ACCEPT", null, Arrays.asList(Tp_procmaterialEnum.ADMRE_ACCEPT, Tp_procmaterialEnum.ADMRE_REPLY)),
    // Tp_procmaterialEnum.ADMRE_APPEND
    ACCEPT_APPEND("accept_append", Tp_proctype.ACCEPT_APPEND, "补正", "补正",
            Tp_categoryEnum.APPEND_UPLOAD.getKey(), "ADMRE_AUDIT_APPEND", null, null),
    // Tp_procmaterialEnum.ARRIVE_INFORM
    ACCEPT_INFORM("accept_inform", Tp_proctype.ACCEPT_INFORM, "告知", "告知",
            Tp_categoryEnum.INFORM_UPLOAD.getKey(), "ADMRE_AUDIT_INFORM", null, null),
    // Tp_procmaterialEnum.ADMRE_NOACCEPT
    ACCEPT_NOACCEPT("accept_noaccept", Tp_proctype.ACCEPT_NOACCEPT, "不予受理", "不予受理",
            Tp_categoryEnum.NOACCEPT_UPLOAD.getKey(), "ADMRE_AUDIT_NOACCEPT", null, null),

    ACCEPT_RESULT("accept_result", Tp_proctype.ACCEPT_RESULT, "撤回", "撤回",
            Tp_categoryEnum.ROLLBACK_UPLOAD.getKey(), "ADMRE_AUDIT_WITHDRAW", null, null),

    ACCEPT_OTHERDEAL("accept_otherdeal", Tp_proctype.ACCEPT_OTHERDEAL, "视为放弃", "视为放弃",
            Tp_categoryEnum.ACCEPTOTHER_UPLOAD.getKey(), "ADMRE_AUDIT_OTHERDEAL", null, null),

    ACCEPT_CHANGE_FIRSTPER("accept_change_firstper", Tp_proctype.ACCEPT_CHANGE_FIRSTPER, "变更承办人", "变更承办人", Tp_categoryEnum.ACCEPT_CHANGE.getKey(), "ACCEPT_CHANGE", null, null),

    ACCEPT_CHANGE_SECONDPER("accept_change_secondper", Tp_proctype.ACCEPT_CHANGE_SECONDPER, "变更协办人", "变更协办人", Tp_categoryEnum.ACCEPT_CHANGE.getKey(), "ACCEPT_CHANGE", null, null),

    /**
     * 审理环节
     */
    HEAR_MEDIATE("hear_mediate", Tp_proctype.HEAR_MEDIATE, "受理后调解", "受理后调解", Tp_categoryEnum.MEDIATE_AFTERUPLOAD.getKey(), "HEAR_MEDIATE", St_admreviewson.MEDIATE,
            null),

    HEAR_TRAWL("hear_trawl", Tp_proctype.HEAR_TRAWL, "查阅复制", "查阅复制", Tp_categoryEnum.TRAWL_UPLOAD.getKey(), "HEAR_TRAWL", St_admreviewson.TRAWL, null),

    // Tp_procmaterialEnum.HEAR_NOTE
    HEAR_SURVEY("hear_survey", Tp_proctype.HEAR_SURVEY, "调查", "调查", Tp_categoryEnum.SURVEY_UPLOAD.getKey(), "HEAR_SURVEY", St_admreviewson.SURVEY,
            null),
    // Tp_procmaterialEnum.HEAR_INQUEST
    HEAR_INQUEST("hear_inquest", Tp_proctype.HEAR_INQUEST, "勘验", "勘验", Tp_categoryEnum.INQUEST_UPLOAD.getKey(), "HEAR_INQUEST", St_admreviewson.INQUEST,
            null),

    HEAR_HEARING("hear_hearing", Tp_proctype.HEAR_HEARING, "听证", "听证", Tp_categoryEnum.HEARING_UPLOAD.getKey(), "HEAR_HEARING", St_admreviewson.HEARING,
            null),
    // Tp_procmaterialEnum.HEAR_DETERMINEAPL, Tp_procmaterialEnum.HEAR_DETERMINE
    HEAR_IDENTIFY("hear_identify", Tp_proctype.HEAR_IDENTIFY, "鉴定", "鉴定", Tp_categoryEnum.IDENTIFY_UPLOAD.getKey(), "HEAR_IDENTIFY", St_admreviewson.IDENTIFY,
           null),
    // Tp_procmaterialEnum.HEAR_STOPAPL, Tp_procmaterialEnum.HEAR_STOP
    HEAR_STOP("hear_stop", Tp_proctype.HEAR_STOP, "停止执行", "停止执行", Tp_categoryEnum.STOP_UPLOAD.getKey(), "HEAR_STOP", St_admreviewson.STOP,
            null),
    // Tp_procmaterialEnum.HEAR_DELAY
    HEAR_DELAY("hear_delay", Tp_proctype.HEAR_DELAY, "延期", "延期", Tp_categoryEnum.DELAY_UPLOAD.getKey(), "HEAR_DELAY", St_admreviewson.DELAY,
            null),
    // Tp_procmaterialEnum.HEAR_HANGUP
    HEAR_REST("hear_rest", Tp_proctype.HEAR_REST, "中止", "中止", Tp_categoryEnum.REST_UPLOAD.getKey(), "HEAR_REST", St_admreviewson.REST,
            null),

    // Tp_procmaterialEnum.HEAR_TERMIN, Tp_procmaterialEnum.HEAR_DECISION, Tp_procmaterialEnum.HEAR_REJECT,Tp_procmaterialEnum.HEAR_PERFORM, Tp_procmaterialEnum.HEAR_REMINDER
    HEAR_DECISION("hear_decision", Tp_proctype.HEAR_DECISION, "决定", "决定", Tp_categoryEnum.DECISION_UPLOAD.getKey(), "HEAR_DECISION", St_admreviewson.DECISION,
            Arrays.asList(Tp_procmaterialEnum.HEAR_LISTENFORM)
    ),

    // Tp_procmaterialEnum.HEAR_REPLYLETTER
    HEAR_REPLY("hear_reply", Tp_proctype.HEAR_REPLY, "被申请人答复", "被申请人答复", "hear_reply", null, null,
            null),

    // Tp_procmaterialEnum.HEAR_WITHDRAW
    HEAR_WITHDRAW("hear_withdraw", Tp_proctype.HEAR_WITHDRAW, "撤回", "撤回", Tp_categoryEnum.WITHDRAW_UPLOAD.getKey(),
            "HEAR_WITHDRAW", St_admreviewson.TOBACK, null),
    // Tp_procmaterialEnum.HEAR_MOBILIZE
    HEAR_MOBILIZE("hear_mobilize", Tp_proctype.HEAR_MOBILIZE, "调卷", "调卷", Tp_categoryEnum.MOBILIZE_UPLOAD.getKey(), "HEAR_MOBILIZE", St_admreviewson.MOBILIZE,
            null),
    // Tp_procmaterialEnum.HEAR_RESTORE
    HEAR_RESTORE("hear_restore", Tp_proctype.HEAR_RESTORE, "恢复", "恢复", Tp_categoryEnum.RESTORE_UPLOAD.getKey(), "HEAR_RESTORE", St_admreviewson.RESTORE,
            null),
    // Tp_procmaterialEnum.ARRIVE_FORCE
    EXECUTE_FORCE_UNIT("execute_force_unit", Tp_proctype.EXECUTE_FORCE_UNIT, "复议机关强制执行", "复议机关强制执行", Tp_categoryEnum.FORCE_UPLOAD.getKey(), "EXECUTE_FORCE", St_admreviewson.FORCEUNIT,
            null),
    // Tp_procmaterialEnum.ARRIVE_FORCE
    EXECUTE_FORCE_LAW("execute_force_law", Tp_proctype.EXECUTE_FORCE_LAW, "委托人民法院强制执行", "委托人民法院强制执行", Tp_categoryEnum.FORCE_UPLOAD.getKey(), "EXECUTE_FORCE", St_admreviewson.FORCELAW,
           null),
    // Tp_procmaterialEnum.HEAR_REMINDER
    EXECUTE_SELF("execute_self", Tp_proctype.EXECUTE_SELF, "自行履行", "自行履行", Tp_categoryEnum.REMINDER_UPLOAD.getKey(), "EXECUTE_SELF", St_admreviewson.SELF,
            null),

    EXECUTE_PERFORM("execute_perform", Tp_proctype.EXECUTE_PERFORM, "责令履行", "责令履行", Tp_categoryEnum.PERFORM_UPLOAD.getKey(), "EXECUTE_PERFORM", St_admreviewson.PERFORM,
            null),

    HEAR_ADVICE("hear_advice", Tp_proctype.HEAR_ADVICE, "听取意见", "听取意见", null, "HEAR_ADVICE", null, null),

    HEAR_TRANSFORM("hear_transform", Tp_proctype.HEAR_TRANSFORM, "程序转换", "程序转换",
            Tp_categoryEnum.TRANSFORM_UPLOAD.getKey(), "HEAR_TRANSFORM", St_admreviewson.TRANSFORM, null),

    HEAR_EXPERT("hear_expert", Tp_proctype.HEAR_EXPERT, "专家论证", "专家论证", null, "HEAR_EXPERT", St_admreviewson.EXPERT, null),

    HEAR_THIRDER("hear_thirder", Tp_proctype.HEAR_THIRDER, "第三人审批", "第三人审批", Tp_categoryEnum.THIRDER_UPLOAD.getKey(), "HEAR_THIRDER", St_admreviewson.THIRDER, null),


    HEAR_CHANGE_FIRTPER("hear_change_firtper", Tp_proctype.HEAR_CHANGE_FIRTPER, "审理变更承办人", "审理变更承办人", Tp_categoryEnum.HEAR_CHANGE_UPLOAD.getKey(), "HEAR_CHANGE", St_admreviewson.PERSONCHANGE, null),

    HEAR_CHANGE_SECONDPER("hear_change_secondper", Tp_proctype.HEAR_CHANGE_SECONDPER, "审理变更协办人", "审理变更协办人", Tp_categoryEnum.HEAR_CHANGE_UPLOAD.getKey(), "HEAR_CHANGE", St_admreviewson.PERSONCHANGE, null),

    SUPERVISE_DECISION("supervise_decision", Tp_proctype.SUPERVISE_DECISION, "复议监督决定", "复议监督决定", null, "SUPERVISE_DECISION", St_admreviewson.DECISION, null);


    private String key;

    private Integer id;

    private String name;

    private String description;

    // 流程节点分类标识
    private String categoryKey;

    // 流程模型key
    private String processkey;

    private Integer status;

    // 需要校验的材料
    private List<Tp_procmaterialEnum> materilas;


    Tp_proctypeEnum(String key, Integer id, String name, String description, String categoryKey, String processkey,
                    Integer status, List<Tp_procmaterialEnum> materilas) {
        this.key = key;
        this.id = id;
        this.name = name;
        this.description = description;
        this.categoryKey = categoryKey;
        this.processkey = processkey;
        this.status = status;
        this.materilas = materilas;
    }


    public static Tp_proctypeEnum getById(Integer id) {
        Tp_proctypeEnum[] proctypeEnums = Tp_proctypeEnum.values();
        for (Tp_proctypeEnum proctypeEnum : proctypeEnums) {
            if (proctypeEnum.id.equals(id)) {
                return proctypeEnum;
            }
        }
        return null;
    }

    public static Tp_proctypeEnum getByKey(String key) {
        Tp_proctypeEnum[] proctypeEnums = Tp_proctypeEnum.values();
        for (Tp_proctypeEnum proctypeEnum : proctypeEnums) {
            if (StringUtils.isNotEmpty(proctypeEnum.key) && proctypeEnum.key.equals(key)) {
                return proctypeEnum;
            }
        }
        return null;
    }


    public static Tp_proctypeEnum getByCategoryKey(String categoryKey) {
        Tp_proctypeEnum[] proctypeEnums = Tp_proctypeEnum.values();
        for (Tp_proctypeEnum proctypeEnum : proctypeEnums) {
            if (StringUtils.isNotEmpty(proctypeEnum.categoryKey) && proctypeEnum.categoryKey.equals(categoryKey)) {
                return proctypeEnum;
            }
        }
        return null;
    }

    public static Tp_proctypeEnum getByStatus(Integer status) {
        Tp_proctypeEnum[] proctypeEnums = Tp_proctypeEnum.values();
        for (Tp_proctypeEnum proctypeEnum : proctypeEnums) {
            if (ObjectUtil.isNotEmpty(proctypeEnum.status) && proctypeEnum.status.equals(status)) {
                return proctypeEnum;
            }
        }
        return null;
    }

    public static Tp_proctypeEnum getByMaterilas(Tp_procmaterialEnum materilas ) {
        Tp_proctypeEnum[] proctypeEnums = Tp_proctypeEnum.values();
        for (Tp_proctypeEnum proctypeEnum : proctypeEnums) {
            if (ObjectUtil.isNotNull(proctypeEnum.getMaterilas()) && proctypeEnum.getMaterilas().contains(materilas)) {
                return proctypeEnum;
            }
        }
        return null;
    }
}
